#ifndef  SHINY_SOUNDMANAGER_HPP
# define SHINY_SOUNDMANAGER_HPP

# include <SFML/Audio.hpp>
# include "soundlist.hpp"
# include "observatory.hpp"

namespace Shiny
{
  struct Sound : public sf::Sound
  {
    Observatory::Signal<Sound*> Ended;
  };

  class SoundManager
  {
    typedef std::list<Sound*> Sounds;

    static SoundManager* _instance;
  public:
    SoundManager() : _maxChannels(500)
    { _instance = this; }

    static SoundManager* Get() { return (_instance); } ;
    
    void         Run(void);
    bool         Play(Sound*);
    void         StopPlaying(Sound*);
    
  private:
    Sounds       _sounds;
    unsigned int _usedChannels;
    unsigned int _maxChannels;
  };

  class MusicManager
  {
    struct Music : public sf::Music
    {
      std::string filename;
    };
    
    typedef std::list<Music*> Musics;

      static MusicManager* _instance;
      MusicManager(void);
      ~MusicManager(void);

    public:
      static MusicManager* Get(void);
      static void          Destroy(void);

      void   Load(const std::string& filename);
      void   Unload(const std::string& filename);
      
      void   Play(const std::string& filename);
    
    private:
      Musics _tracks;
      Music* _currentTrack;
  };
}

#endif
